
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "esp_system.h"
#include "esp_wifi.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "SSB_sys_def.h"
#include "SSB_socket.h"
#include "SSB_wifi.h"
#include "SSB_system.h"

int socket_ready = 0;
int socket_init = 0;

void on_received_socket_data(char *data, int len)
{
}

void on_socket_status_change(int status)
{
    socket_ready = status;
}

void say_hello()
{
    while (1)
    {
        vTaskDelay(3000 / portTICK_PERIOD_MS);
        if (socket_ready)
        {
            SSB_socket_write("hi opcol\r\n", strlen("hi opcol\r\n"));
        }
    }
}

void on_wifi_state_change(int state)
{
    if (state == SSB_NET_CONNECTED_STATE)
    {
        if (socket_init == 0)
        {
            SSB_init_socket(on_received_socket_data, on_socket_status_change);
            socket_init = 1;
        }
    }
}

void app_main()
{
    extern char socket_server[128];
    strcpy(&socket_server[0], "192.168.12.116"); //服务器地址，用户需要改变为自己的服务器地址
    SSB_init_system();
    SSB_init_wifi(on_wifi_state_change, 1, 1);

    xTaskCreate(say_hello, "say_hello_task", 1024 * 3, NULL, 8, NULL);
}
